package qingke.command;

import java.util.HashMap;
import java.util.Map;

import qingke.command.CommandFactory.CommandCode;
import qingke.command.impl.ExitCommand;
import qingke.command.impl.HelpCommand;
import qingke.command.impl.LoginCommand;
import qingke.command.impl.SignupCommand;

public class SystemCommandFactory extends CommandFactory {

	private static Map<CommandCode,Class<? extends Command>> commandMap = new HashMap();	
	
	static {
		commandMap.put(CommandCode.EXIT, ExitCommand.class);
		commandMap.put(CommandCode.HELP, HelpCommand.class);
		commandMap.put(CommandCode.LOGIN, LoginCommand.class);
		commandMap.put(CommandCode.SIGNUP, SignupCommand.class);
	}
	@Override
	public Command buildCommand(CommandCode code) {
		Class<? extends Command> cmdClass = commandMap.get(code);
		if (cmdClass != null) {
			try {
				return cmdClass.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

}
